{extend name="iframe" /}

{block name="body"}
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
	style="padding: 20px 30px 0 0;">
	<form action="{:request()->url()}" method="post" class="xn_ajax layui-form" data-type="open">
		<div class="layui-form-item">
			<label class="layui-form-label">管理组</label>
			<div class="layui-input-block">
				{foreach name="group_data" item="v" key="k"}
				{if $k neq 0}
				<input class="xb-icheck" type="checkbox" name="group_ids[]" value="{$v.id}" {in name="v.id"
					value="$user_group_ids" } checked="checked" {/in} title="{$v.title}" lay-skin="primary">
				<!-- <input type="radio" name="group_ids" value="1" title="{$v.title}" lay-filter="group_ids" {in name="v.id"
					value="$user_group_ids" } checked{/in}> -->
				{/if}
				{/foreach}
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">账号类型</label>
			<div class="layui-input-block" id="type">
				<input type="radio" name="user_type" value="1" title="平台" lay-filter="user_type" {if condition="$user_data['user_type'] eq '1'"
					}checked{/if}>
				<input type="radio" name="user_type" value="2" title="学校" lay-filter="user_type" {if condition="$user_data['user_type'] eq '2'"
					}checked{/if}>
			</div>
		</div>
		<div class="layui-form-item content" id="usertype1">
			<label class="layui-form-label">供应商</label>
			<div class="layui-input-inline">
				<select name="type_id" lay-verify="required" lay-filter="type_id">
					<option value="0">请选择</option>
					{foreach name="info" item="vo" key="k"}
					<option value="{$vo.id}" {if condition="$vo['id'] eq $user_data['type_id']" }selected{/if}>{$vo.title|raw}
					</option>
					{/foreach}
				</select>
			</div>
		</div>
		<div class="layui-form-item content" id="usertype2">
			<label class="layui-form-label">学校</label>
			<div class="layui-input-inline">
				<select name="type_id" lay-verify="required" lay-filter="type_id">
					<option value="0">请选择</option>
					{foreach name="school" item="vo" key="k"}
					<option value="{$vo.id}" {if condition="$vo['id'] eq $user_data['type_id']" }selected{/if}>{$vo.title}
					</option>
					{/foreach}
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">账号</label>
			<div class="layui-input-inline">
				<input type="text" name="username" lay-verify="required" placeholder="" autocomplete="off"
					class="layui-input" value="{$user_data.username}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">密码</label>
			<div class="layui-input-inline">
				<input type="password" name="password" placeholder="" autocomplete="off" class="layui-input" value="">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-inline">
				<input type="checkbox" lay-verify="required" lay-filter="status" name="status" lay-skin="switch"
					lay-text="正常|禁止" value="1" {if condition="$user_data['status'] eq 1" }checked{/if}>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" lay-submit class="layui-btn">保存</button>
			</div>
		</div>
	</form>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
	layui.use(['form'], function(){
	    var form = layui.form;
	    var $ = layui.jquery;
		$('.content').hide();
	    // 初始化渲染
	    form.render(); 
	
	    // 监听账号类型单选框
	    form.on('radio(user_type)', function(data){
	        console.log('当前用户类型：', data.value);
	        // 根据值显示/隐藏相关内容
	        $('.content').hide();
	        $('#usertype' + data.value).show();
	    });
	
	    // 初始化显示
	    var initVal = $('input[name="user_type"]:checked').val();
	    $('#usertype' + initVal).show();
	});
</script>
{/block}